# -*- coding: utf-8 -*-
# @Time : 2022/4/6 21:03
# @Author : Liuqing
# @File : 剑指Offer04)二维数组中的查找.py
# @Software : PyCharm


class Solution:
    def findNumberIn2DArray(self, matrix, target):
        if not matrix or len(matrix) == 0 or len(matrix[0]) == 0:
            return False

        rows = len(matrix)
        columns = len(matrix[0])

        row, column = 0, columns - 1
        while row < rows and column >= 0:
            current = matrix[row][column]
            if current == target:
                return True
            elif current > target:
                column -= 1
            else:
                row += 1

        return False
